import { createBrowserRouter,Navigate } from "react-router-dom";
import CityList from "../pages/cityList";
import BaseLayout from "../pages/baseLayout";
import Login from "../pages/login";
import Rent from "../pages/rent";
import RentAdd from "../pages/rentadd";
import Favorate from "../pages/favorate";
import { lazy,Suspense } from "react";
import ErrorPage from "../components/errorpage";
import NotFoundPage from "../components/404page";
import Home from '../pages/home'
const News = lazy(()=> import("../pages/news"))
const Profile = lazy(()=> import("../pages/profile"))
const HouseList = lazy(()=> import("../pages/houseList"))
const HouseDetail = lazy(()=> import("../pages/housedetail"))
const Map =lazy(()=> import("../pages/map"))



const router = createBrowserRouter([
    {
        path:'/',
        element: <BaseLayout />,
        children: [
            {
                index: true,
                element: <Navigate to='/home' />
            },
            {
                path:'/home',
                element: <Home />
            },
            {
                path:'/news',
                element:<Suspense fallback={'加载中'}><News /></Suspense>
            },
            {
                path:'/me',
                element: <Suspense fallback={'加载中'}><Profile /></Suspense>,
            },
            {
                path:'/list',
                element: <Suspense fallback={'加载中'}><HouseList /></Suspense>,
            }
        ]
    },
    {
        path:'/map',
        element: <Suspense fallback={'加载中'}><Map /></Suspense>,
    },
    {
        path:'/citylist',
        element: <CityList />,
    },
    {
        path:'/detail/:id',
        element: <Suspense fallback={'加载中'}><HouseDetail /></Suspense>,
    },
    {
        path:'/login',
        element: <Login />,
    },
    {
        path:'/rent',
        element: <Rent />,
    }
    ,
    {
        path:'/rent/add',
        element: <RentAdd />,
    },
    {
        path:'/favorate',
        element: <Favorate />,
    },
    {
        path:'/error',
        element: <ErrorPage />,
    },
    {
        path:'*',
        element: <NotFoundPage />,
    }
    
])

export default router